package com.haredot.service.impl;

import com.haredot.dto.AdvertDTO;
import com.haredot.entity.Advert;
import com.haredot.mapper.AdvertMapper;
import com.haredot.service.AdvertService;
import com.haredot.vo.R;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class AdvertServiceImpl implements AdvertService {

    @Resource
    private AdvertMapper advertMapper ;

    @Override
    public R<?> queryAverts() {
        // 查询所有的 轮播图
        List<AdvertDTO> advertDTOS = advertMapper.findAdverts();
        return R.<AdvertDTO>ok().data(advertDTOS);
    }

    @Override
    public R<?> updateAdvert(Advert advert) {
        int len = this.advertMapper.update(advert) ;
        return len == 1 ? R.ok().build() : R.fail().build();
    }

    @Override
    public R<?> saveAdvert(Advert advert) {
        int len = this.advertMapper.save(advert) ;
        return len == 1 ? R.ok().build() : R.fail().build();
    }

    @Override
    public R<?> removeById(Long id) {
        int len = this.advertMapper.deleteById(id) ;
        return len == 1 ? R.ok().build() : R.fail().build();
    }

    @Override
    public R<?> removeByIds(List<Long> ids) {
        int len = this.advertMapper.batchDeleteByIds(ids) ;
        return len > 0 ? R.ok().build() : R.fail().build();
    }
}
